package cn.gcxy.handler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gcxy.entity.Type;
import cn.gcxy.service.TypeService;

@Controller()
@RequestMapping(value="type")
public class TypeHandler {
	
	@Autowired
	@Qualifier("typeService")
	TypeService typeService;

	@ResponseBody
	@RequestMapping("initType")
	public List<Map<String, Object>> initType(){
		List<Map<String, Object>> maps = new ArrayList<Map<String,Object>>();
		List<Type> tpes = typeService.queryAllType();
		Map<String, Object> map;
		for (Type type : tpes) {
			map = new HashMap<String, Object>();
			map.put("id", type.getId());
			map.put("name", type.getName());
			map.put("pId", type.getPid());
			if(type.getPid() == "0") {
				map.put("isParent", "true");
			}else {
				map.put("isParent", "false");
			}
			maps.add(map);
		}
		
//		for (XtYyxx00 xtYyxx00 : xtYyxx00s) {
//			Map<String,Object> map = new HashMap<String, Object>();
//			map.put("id", xtYyxx00.getYyid00());
//			map.put("pId", "0");
//			map.put("name", xtYyxx00.getYyqc00());
//			map.put("isParent", "true");
//			maps.add(map);
//		}

		return maps;
	}
}
